package com.atguigu.behavior.command;

public class RemoteController {
    private final Command[] onCommands;
    private final Command[] offCommands;

    private Command undoCommand;

    public RemoteController() {
        onCommands=new Command[5];
        offCommands=new Command[5];
        for (int i = 0; i < 5; i++) {
            NoCommand noCommand = new NoCommand();
            onCommands[i]=noCommand;
            offCommands[i]=noCommand;
        }
    }

    public void setCommand(int no,Command onCommand,Command offCommand){
        onCommands[no]=onCommand;
        offCommands[no]=offCommand;
    }


    public void onButtonWasPushed(int no){
        onCommands[no].execute();
        undoCommand=onCommands[no];
    }

    public void offButtonWasPushed(int no){
        offCommands[no].execute();
        undoCommand=offCommands[no];
    }

    public void undoButtonWasPushed(){
        undoCommand.undo();
    }

}
